NB: The worksheet has beed developed and prepared by Maxim Romanov for the course “R for Historical Research” (U Vienna, Spring 2019)
We will need some new libraries that are developed for working with maps. You may want to install those libraries outside of the notebook, so that it does not try to reinstall them everytime you knit it.
#install.packages(c("cowplot", "googleway", "ggplot2", "ggrepel", "ggspatial", "libwgeom", "sf", "rnaturalearth", "rnaturalearthdata", "rnaturalearthhires", "rgeos"))
library(tinytex)
library("ggplot2")
theme_set(theme_bw())
library("sf")
## Linking to GEOS 3.6.1, GDAL 2.2.3, PROJ 4.9.3
The libraries below have the necessary geographical data, so let’s load them and create a working variable.
library("rnaturalearth")
library("rnaturalearthdata")
#world <- ne_countries(scale = "large", returnclass = "sf")
world <- ne_countries(scale = "medium", returnclass = "sf")
Now we can create our first and simple map with just a couple of lines of code. See how easy it is.
ggplot(data = world) +
geom_sf()
We can add additional information to our map to make it more informative. Look at the ggtitle(): we can combine necessary numbers with textual annotations.
ggplot(data = world) +
geom_sf() +
xlab("Longitude") + ylab("Latitude") +
ggtitle("World map", subtitle = paste0("(", length(unique(world$name)), " countries)"))
Color and fill determine the colors of “borders” and “areas” within.
ggplot(data = world) +
geom_sf(color = "grey", fill = "grey")
Since we have some demographic data, we can visualize it with colors. You can google other color scales.
ggplot(data = world) +
geom_sf(aes(fill = pop_est)) +
scale_fill_viridis_c(option = "magma", trans = "sqrt")
We can also select a projection like shown in the code below. For more details, check references given below.
ggplot(data = world) +
geom_sf(color = "grey", fill = "grey") +
coord_sf(crs = st_crs(3035))
We can focus our map on a specific area of the globe.
xlim=c(85,130); ylim=c(10,45)
ggplot(data = world) +
geom_sf(color="grey", fill="grey") +
coord_sf(xlim = xlim, ylim = ylim, expand = FALSE)
And add a scale and a North arrow, to make it look a bit cooler.
library("ggspatial")
xlim=c(-12,40); ylim=c(30,60)
ggplot(data = world) +
geom_sf(fill="grey60", color="grey60") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
coord_sf(xlim = xlim, ylim = ylim, expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5), panel.background = element_rect(fill = "grey90"))
Let’s get some data first. The data comes from: http://atlantides.org/downloads/pleiades/dumps/. Can you find the description of data? (If description is already available it may make it easier for you to figure out what can be done with it.)
data_link <- "http://atlantides.org/downloads/pleiades/dumps/pleiades-locations-latest.csv.gz"
download.file(data_link,"pleiades-locations-latest.csv.gz")
locsRaw <- read.csv(gzfile("pleiades-locations-latest.csv.gz"),stringsAsFactors=F,header=T,sep=',')
The data contains geolocations, which are also categorized chronologically, The chronology is rather tricky: there are several main periods, but they are not used discretionally as many places often exist in multiple periods. These look as follows:
archaic (750-550BC)classical (550-330BC)hellenistic-republican (330-30BC)roman (30BC-300CE)late-antique (300-640CE)You can also try to split this data into other periods based on the minDate and maxDate, but that is a bit more complicated.
Let’s try to add it to our base map.
xlim <- c(-12,55); ylim=c(20,60)
plot <- ggplot(data = world) +
geom_sf(fill="grey70", color="grey70") +
geom_point(data=locsRaw,color="red",alpha=.1,size=.5,aes(y=reprLat,x=reprLong)) +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
coord_sf(xlim = xlim, ylim = ylim, expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
ggtitle("Data from Pleiades", subtitle = "Density of Geographical Information")
plot
Let’s check what is in the data (always try to find the official description of data!).
summary(locsRaw)
## authors bbox created
## Length:39626 Length:39626 Length:39626
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## creators currentVersion description
## Length:39626 Min. : 0.0000 Length:39626
## Class :character 1st Qu.: 0.0000 Class :character
## Mode :character Median : 1.0000 Mode :character
## Mean : 0.8305
## 3rd Qu.: 1.0000
## Max. :18.0000
## NA's :113
## featureType geometry id
## Length:39626 Length:39626 Length:39626
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## locationPrecision locationType maxDate
## Length:39626 Length:39626 Min. :-9000.0
## Class :character Class :character 1st Qu.: 300.0
## Mode :character Mode :character Median : 640.0
## Mean : 483.1
## 3rd Qu.: 640.0
## Max. : 2100.0
## NA's :3006
## minDate modified path
## Min. :-2600000.0 Length:39626 Length:39626
## 1st Qu.: -330.0 Class :character Class :character
## Median : -30.0 Mode :character Mode :character
## Mean : -276.9
## 3rd Qu.: -30.0
## Max. : 1918.0
## NA's :3006
## pid reprLat reprLatLong reprLong
## Length:39626 Min. :-20.00 Length:39626 Min. :-16.910
## Class :character 1st Qu.: 36.25 Class :character 1st Qu.: 8.013
## Mode :character Median : 39.06 Mode :character Median : 17.643
## Mean : 39.51 Mean : 19.890
## 3rd Qu.: 43.75 3rd Qu.: 30.699
## Max. : 62.50 Max. :105.152
## NA's :7342 NA's :7342
## tags timePeriods timePeriodsKeys
## Length:39626 Length:39626 Length:39626
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
## timePeriodsRange title uid
## Length:39626 Length:39626 Length:39626
## Class :character Class :character Class :character
## Mode :character Mode :character Mode :character
##
##
##
##
We check what types of things are mappable. In this dataset, types of objects are described in the featureType column.
unique(locsRaw$featureType)
## [1] "settlement,"
## [2] "temple-2,"
## [3] "unknown"
## [4] "island"
## [5] "settlement"
## [6] "villa,"
## [7] "cape"
## [8] "mountain,"
## [9] "river,"
## [10] "station,"
## [11] "aqueduct,"
## [12] "settlement-modern"
## [13] "tumulus,"
## [14] "island,"
## [15] "cemetery,"
## [16] "mountain"
## [17] "fort"
## [18] "tomb,"
## [19] "tomb"
## [20] "archipelago,"
## [21] "water-open,"
## [22] "bath,"
## [23] "church,"
## [24] "monument,"
## [25] "monument"
## [26] "architecturalcomplex"
## [27] "cemetery"
## [28] "bath"
## [29] "tumulus"
## [30] "mine,"
## [31] "fountain"
## [32] "settlement-modern,"
## [33] "sanctuary,"
## [34] "architecturalcomplex,"
## [35] "unknown,"
## [36] "temple-2"
## [37] "peninsula"
## [38] "theatre,"
## [39] "road,"
## [40] "townhouse,"
## [41] "settlement,settlement-modern"
## [42] "plaza"
## [43] "plateau"
## [44] "arch,"
## [45] "hill,"
## [46] "fort,"
## [47] "military-installation-or-camp-temporary,"
## [48] "church"
## [49] "tunnel,monument"
## [50] "cave,monument"
## [51] "findspot,"
## [52] "forest"
## [53] "mine"
## [54] "city-wall,"
## [55] "villa"
## [56] "river"
## [57] "station"
## [58] "spring"
## [59] "lagoon,"
## [60] "architecturalcomplex,bath,"
## [61] "bridge,"
## [62] "aqueduct,bridge,"
## [63] "aqueduct"
## [64] "bridge"
## [65] "cemetery,church,"
## [66] "dam,"
## [67] "island,settlement,port,"
## [68] "city-wall"
## [69] "theatre"
## [70] "production,"
## [71] "settlement,nuraghe,"
## [72] "canal,"
## [73] "townhouse"
## [74] "sanctuary"
## [75] "amphitheatre,theatre,"
## [76] "nuraghe"
## [77] "fountain,"
## [78] "nuraghe,"
## [79] "plaza,"
## [80] "cape,"
## [81] "lake,"
## [82] ""
## [83] "settlement,urban,"
## [84] "settlement,sanctuary"
## [85] "isthmus"
## [86] "townhouse,settlement"
## [87] "cistern,"
## [88] "amphitheatre,"
## [89] "pyramid,tomb,"
## [90] "settlement,settlement-modern,"
## [91] "architecturalcomplex,wall,sanctuary,"
## [92] "bath,villa"
## [93] "region,"
## [94] "settlement,city-wall"
## [95] "pass,"
## [96] "marsh-wetland"
## [97] "people,"
## [98] "stadion,"
## [99] "lake"
## [100] "settlement,sanctuary,"
## [101] "city-gate"
## [102] "circus,"
## [103] "earthwork,"
## [104] "settlement,port,"
## [105] "fort,settlement"
## [106] "city-wall,city-gate,"
## [107] "mosque,"
## [108] "hill"
## [109] "amphitheatre"
## [110] "arch"
## [111] "basilica,"
## [112] "ekklesiasterion"
## [113] "pyramid,architecturalcomplex,cemetery"
## [114] "unknown,settlement-modern,architecturalcomplex"
## [115] "church-2,"
## [116] "architecturalcomplex,sanctuary"
## [117] "abbey"
## [118] "pyramid"
## [119] "bath,production"
## [120] "gymnasium,"
## [121] "church-2"
## [122] "road"
## [123] "palaistra,"
## [124] "garden-hortus,"
## [125] "church-2,sanctuary"
## [126] "hill,tumulus"
## [127] "taberna-shop,"
## [128] "temple-2,architecturalcomplex,"
## [129] "basilica"
## [130] "city-gate,"
## [131] "water-inland,"
## [132] "temple"
## [133] "settlement,temple-2"
## [134] "lighthouse"
## [135] "cave,sanctuary,"
## [136] "cave"
## [137] "shrine"
## [138] "cistern"
## [139] "plaza,basilica,"
## [140] "fort-group"
## [141] "abbey-church"
## [142] "region"
## [143] "region,peninsula,"
## [144] "cave,settlement,sanctuary"
## [145] "cave,"
## [146] "port,settlement,"
## [147] "marsh-wetland,"
## [148] "acropolis"
## [149] "architecturalcomplex,temple-2,"
## [150] "taberna-shop,townhouse"
## [151] "settlement,production,"
## [152] "fort,earthwork"
## [153] "cemetery,villa,"
## [154] "basilica,architecturalcomplex,"
## [155] "cairn,"
## [156] "theatre,sanctuary,"
## [157] "architecturalcomplex,sanctuary,"
## [158] "urban,settlement,"
## [159] "sanctuary,temple-2"
## [160] "mountain,peninsula,"
## [161] "fort,settlement,"
## [162] "circus"
## [163] "region,province"
## [164] "cemetery,settlement,"
## [165] "temple-2,sanctuary,"
## [166] "water-open"
## [167] "plain,"
## [168] "valley,"
## [169] "wall-2,city-wall,"
## [170] "city-wall,wall-2,"
## [171] "theatre,tomb,"
## [172] "taberna-shop"
## [173] "ekklesiasterion,"
## [174] "sanctuary,nuraghe,"
## [175] "production"
## [176] "settlement,island"
## [177] "taberna-shop,townhouse,"
## [178] "port,"
## [179] "plaza,cistern,city-wall,"
## [180] "mountain,settlement,"
## [181] "plaza,settlement"
## [182] "estate,"
## [183] "temple-2,tomb,"
## [184] "cemetery,tumulus"
## [185] "mosque,plaza,"
## [186] "mountain,tomb,"
## [187] "wall-2,"
## [188] "unknown,settlement,"
## [189] "treasury,"
## [190] "cape,settlement,"
## [191] "settlement,mountain,"
## [192] "hill,settlement,sanctuary,"
## [193] "settlement,plaza,sanctuary,"
## [194] "mine,fort,"
## [195] "oasis,"
## [196] "temple-2,architecturalcomplex"
## [197] "temple,"
## [198] "fort,sanctuary,"
## [199] "plaza,cemetery,temple-2,"
## [200] "tomb,cemetery,"
## [201] "fort,city-wall,"
## [202] "pyramid,tomb"
## [203] "sanctuary,settlement"
## [204] "marsh-wetland,salt-pan-salina"
## [205] "earthwork"
## [206] "military-installation-or-camp-temporary"
## [207] "shrine,"
## [208] "stoa,"
## [209] "bath,cistern,"
## [210] "plaza,theatre,sanctuary,"
## [211] "archipelago"
## [212] "well,"
## [213] "estate"
## [214] "port,settlement"
## [215] "findspot"
## [216] "stadion"
## [217] "reservoir,"
## [218] "settlement,plaza,theatre,"
## [219] "settlement,fort,"
## [220] "city-gate,city-wall,"
## [221] "wall-2"
## [222] "port"
## [223] "mountain,monument"
## [224] "settlement-modern,settlement"
## [225] "settlement-modern,bridge"
## [226] "plain"
## [227] "tunnel"
## [228] "fountain,sanctuary,"
## [229] "villa,sanctuary,"
## [230] "architecturalcomplex,fountain,stoa,sanctuary,"
## [231] "plaza,architecturalcomplex,"
## [232] "sanctuary,temple-2,"
## [233] "villa,bath,cistern,production,"
## [234] "church-2,tomb,"
## [235] "hill,fort,"
## [236] "settlement,hill,"
## [237] "valley"
## [238] "peninsula,"
## [239] "forest,"
## [240] "settlement,tomb"
## [241] "station,fort,"
## [242] "causeway,"
## [243] "tomb,cairn,"
## [244] "mountain,hill,"
## [245] "bath,mine"
## [246] "plaza,theatre"
## [247] "treasury"
## [248] "spring,"
## [249] "church,tomb,"
## [250] "estuary,"
## [251] "cave,sanctuary"
## [252] "tunnel,wall,"
## [253] "unknown,fort"
## [254] "province,"
## [255] "canal"
## [256] "dam"
## [257] "architecturalcomplex,villa,"
## [258] "townhouse,settlement,"
## [259] "stadion, stadium,"
## [260] "settlement,bath,"
## [261] "tomb,tumulus,"
## [262] "acropolis,architecturalcomplex,"
## [263] "temple-2,church-2,"
## [264] "settlement,monument"
## [265] "settlement,fort"
## [266] "tomb,villa"
## [267] "temple,church,"
## [268] "bay"
## [269] "cape,mountain,"
## [270] "settlement,port"
## [271] "cemetery,settlement"
## [272] "water-inland"
## [273] "lighthouse,"
## [274] "theatre,plaza,sanctuary,"
## [275] "sanctuary,settlement,"
## [276] "architecturalcomplex,theatre,"
## [277] "settlement,bath,sanctuary,"
## [278] "pass"
## [279] "plateau,"
You can use this line of code to check what kind of information is stored in other columns.
Now we can select some specific feature we are interested in and add this data to our cartogram. As you can see, however, the data is quite messy and makes things rather difficult. So, for filtering our data it is best to use regular expressions like shown below. You can use nrow() to count how many of those items are in the data mapping some low frequency objects may not be very informative.
locs=locsRaw[ with(locsRaw, grepl("\\bfort\\b",featureType)),]
nrow(locs)
## [1] 529
We now can add anther layer of some specific data. Let’s try forts, which we have just created above.
xlim=c(-12,55); ylim=c(20,60)
ggplot(data = world) +
geom_sf(fill="grey70", color="grey70") +
geom_point(data=locsRaw,color="grey20",alpha=.1,size=.1,aes(y=reprLat,x=reprLong)) +
geom_point(data=locs,color="red",alpha=.75,size=.5,aes(y=reprLat,x=reprLong)) +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
coord_sf(xlim = xlim, ylim = ylim, expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("") + ylab("") +
ggtitle("Forts from Pleiades", subtitle = "Density of Geographical Information")
Let’s check whether there are/were any forts on the territory of modern-day Austria.
#looks for austria in the world dataset
austria <- subset(world, admin == "Austria")
# defines the dataset
ourPlot <- ggplot(data = austria) +
# sets the color of the map in different grey shades for borders and fill
geom_sf(fill="grey70", color="grey50") +
#adds geom point from data locsRaw and log lat from this file as variables
geom_point(data=locsRaw,color="grey20",alpha=.25,size=.15,aes(y=reprLat,x=reprLong)) +
#the earlier subset "locs" provides data for forts only
geom_point(data=locs,color="red",alpha=.75,size=1,aes(y=reprLat,x=reprLong)) +
#adds another geom point for showing vienna on the map
geom_point(color="black",alpha=1,shape=1, size=3,aes(y=48.210033,x=16.363449)) +
# adds text and labels were Vienna text is slightly outside the coordinates
geom_text(x=16.363449+.5, y=48.210033+.1, label="vienna", color="black", size=4) +
coord_sf(xlim = c(7.5,17.5), ylim = c(46,50), expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "bl", width_hint = 0.25) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Ancient and Early Medieval Forts", subtitle = "Zooming on Modern Austria")
ourPlot
# saves the graph in a file
ggsave(file="forts_in_austria.png",plot=ourPlot,dpi=300,width=7,height=5)
By the way, we can store the plot into a variable and then reuse it. This is convenient for saving: we can use ggsave() as shown above to save our plot into a separate image. Check the folder with your R Notebook there should be a file called forts_in_austria.png. There is a variety of parameters that you can adjust to get the exact quality of your image that you need. Check ?ggsave for more details (or google it).
Now, let’s do some exercises.
archaic (750-550BC)classical (550-330BC)hellenistic-republican (330-30BC)roman (30BC-300CE)late-antique (300-640CE)austria <- subset(world, admin == "Austria")
locs=locsRaw[ with(locsRaw, grepl("\\bfort\\b",featureType)),]
locsPer=locs[ with(locs, grepl("\\broman\\b",timePeriodsKeys)),]
ourPlot <- ggplot(data = austria) +
geom_sf(fill="grey70", color="grey50") +
geom_point(data=locsRaw,color="grey20",alpha=.25,size=.15,aes(y=reprLat,x=reprLong)) +
#geom_point(data=locs,color="red",alpha=.75,size=1,aes(y=reprLat,x=reprLong)) +
geom_point(data=locsPer,color="blue",alpha=.75,size=1,aes(y=reprLat,x=reprLong)) +
geom_point(color="black",alpha=1,shape=1, size=3,aes(y=48.210033,x=16.363449)) +
geom_text(x=16.363449+.5, y=48.210033+.1, label="vienna", color="black", size=4) +
coord_sf(xlim = c(7.5,17.5), ylim = c(46,50), expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "bl", width_hint = 0.25) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Ancient and Early Medieval Forts", subtitle = "Zooming on Modern Austria")
ourPlot
## Warning: Removed 7342 rows containing missing values (geom_point).
ggsave(file="forts_in_austria_period_period.png",plot=ourPlot,dpi=300,width=7,height=5)
## Warning: Removed 7342 rows containing missing values (geom_point).
# narrow the data down to long lat were the wall is
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
locsRaw
hadrian <- locsRaw %>%
filter(reprLong > -5 & reprLong < 1) %>%
filter(reprLat > 54.5 & reprLat < 55.5)
library(ggplot2)
library(ggspatial)
gb <- subset(world, admin == "United Kingdom")
locs=locsRaw[ with(locsRaw, grepl("\\bfort\\b",featureType)),]
locsWall=locsRaw[ with(locsRaw, grepl("\\bunknown\\b",featureType)),]
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey70", color="grey50") +
#geom_point(data=locsRaw,color="pink",alpha=.25,size=.15,aes(y=reprLat,x=reprLong)) +
geom_point(data=locs,color="red",alpha=.75,size=1,aes(y=reprLat,x=reprLong)) +
geom_point(data=locsWall,color="blue",alpha=.75,size=1,aes(y=reprLat,x=reprLong)) +
#geom_point(color="black",alpha=1,shape=1, size=3,aes(y=48.210033,x=16.363449)) +
#geom_text(x=16.363449+.5, y=48.210033+.1, label="vienna", color="black", size=4) +
coord_sf(xlim = c(-4,0), ylim = c(53,57), expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "bl", width_hint = 0.25) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Hadrians Wall or THE WALL", subtitle = "watch out for white walkers")
ourPlot
## Warning: Removed 7335 rows containing missing values (geom_point).
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="forts_in_hadrians_wall.png",plot=ourPlot,dpi=300,width=7,height=5)
## Warning: Removed 7335 rows containing missing values (geom_point).
## Scale on map varies by more than 10%, scale bar may be inaccurate
Explore Pleiades dataset and create three maps of something interesting that you discover.
Plot 1: Plot that shows Europe, North Africa and parts of Asia with an timelaps of forts that were build in different timeperiods. (but also do not forget to add all necessary information into the map/cartogram).
#install.packages("gifski")
library(gifski)
library(gganimate)
library(ggplot2)
library(ggspatial)
library(dplyr)
# This first part search for regular expression for all time periods of "timePeriodsKeys" that are relevant.
locsPeriods=locsRaw[ with(locsRaw, grepl("\\broman\\b|\\bclassical\\b|\\barchaic\\b|\\blate-antique\\b|\\hellenistic-republican\\b",timePeriodsKeys)),]
# The second part searches for a specifc first letter in "timePeriods" or a specifc first letter plus any other following letter. E.g. R = Roman
# RL = Roman,Late-Antique
locsArchaic=locsPeriods[ with(locsPeriods, grepl("^A|A\\w+",timePeriods)),]
locsRoman=locsPeriods[ with(locsPeriods, grepl("^R|R\\w+",timePeriods)),]
locsClassical=locsPeriods[ with(locsPeriods, grepl("^C|C\\w+",timePeriods)),]
locsHellenisticRepublican=locsPeriods[ with(locsPeriods, grepl("^H|H\\w+",timePeriods)),]
locsLateAntique=locsPeriods[ with(locsPeriods, grepl("^L|L\\w+",timePeriods)),]
# Before I could work on the plot I had to clean the data and add a new column called "epoch". The new variable assigns observatoins to one specific timeperiod.
# I assumed that the varialbe "timePeriods" does provide shortcuts for timePeriodsKeys and the first letter in "timePeriods" would be the period in which a fort, # or settlement, or any sight was built first. E.g. "RL" = "Romen,Late-Antique" will be assiged to the value "roman".
locsArchaic <- locsArchaic %>%
select(uid) %>%
mutate(epoch = "archaic")
locsRoman <- locsRoman %>%
select(uid) %>%
mutate(epoch = "roman")
locsClassical <- locsClassical %>%
select(uid) %>%
mutate(epoch = "classical")
locsHellenisticRepublican <- locsHellenisticRepublican %>%
select(uid) %>%
mutate(epoch = "hellenistic-republican")
locsLateAntique <- locsLateAntique %>%
select(uid) %>%
mutate(epoch = "late-antique")
# The following section joins the resulting different data frames fully into one
joinLocs <- full_join(locsClassical, locsArchaic)
## Joining, by = c("uid", "epoch")
joinLocs <- full_join(joinLocs, locsRoman)
## Joining, by = c("uid", "epoch")
joinLocs <- full_join(joinLocs, locsLateAntique)
## Joining, by = c("uid", "epoch")
joinLocs <- full_join(joinLocs, locsHellenisticRepublican)
## Joining, by = c("uid", "epoch")
# The next section left_joins the larger database in "locsPeriods" with the newly "joinLocs" data frame.
joinedLocs <- left_join(locsPeriods, joinLocs, by = "uid")
# Finally filter for specifc timeperiods to avoid NAs
locsNicelyCleaned <- joinedLocs %>%
filter(epoch == c("classical", "roman", "late-antique", "hellenistic-republican", "archaic"))
## Warning in epoch == c("classical", "roman", "late-antique", "hellenistic-
## republican", : longer object length is not a multiple of shorter object
## length
# searches for "fort" with regular expression to receive forts only
locs=locsNicelyCleaned[ with(locsNicelyCleaned, grepl("\\bfort\\b",featureType)),]
# Plotting
# creates a plot with a world map
ourPlot <- ggplot(data = world) +
# creates the colors for the world map
geom_sf(fill="grey70", color="grey50") +
# creates plottings points from the "locs" dataframe and adds a dot on specific coordinates
geom_point(data=locs,alpha=.7,size=2,aes(y=reprLat,x=reprLong,color=epoch)) +
# defines the area of the world map that is displayed
coord_sf(xlim = c(-15,50), ylim = c(20,75), expand = FALSE) +
# defines the theme of the plot
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
# assigns names to x and y axis
xlab("Longitude") + ylab("Latitude") +
# creates a annotation scale
annotation_scale(location = "bl", width_hint = 0.25) +
# creates an north arrow for the annotation
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
# creates the title for the plot
ggtitle("Forts timelaps {closest_state}", subtitle = "Frame {frame} of {nframes}")+
# changes the title for the colors which are the different timeperiods of the epoch column
labs(color = "Timeperiods")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
# animation that uses the new "epoch" column to display forts of various timperiods one by one
# transition_states(epoch,
# transition_length = 3,
# state_length = 100,
# wrap = FALSE)+
# enter_fade()+
# exit_fade()
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="forts_in_different_periods.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
locsChurch=locsNicelyCleaned[ with(locsNicelyCleaned, grepl("\\bchurch\\b",featureType)),]
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey70", color="grey50") +
geom_point(data=locsChurch,size=2,aes(y=reprLat,x=reprLong,color=epoch)) +
coord_sf(xlim = c(-15,50), ylim = c(20,75), expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "bl", width_hint = 0.25) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Church timelaps {closest_state}", subtitle = "Frame {frame} of {nframes}")+
labs(color = "Timeperiods")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
# transition_states(epoch,
# transition_length = 3,
# state_length = 100,
# wrap = FALSE)+
# enter_fade()+
# exit_fade()
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="churches_in_different_timeperiods.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
locsSettlement=locsNicelyCleaned[ with(locsNicelyCleaned, grepl("\\bsettlement\\b",featureType)),]
locsChurch=locsNicelyCleaned[ with(locsNicelyCleaned, grepl("\\bchurch\\b",featureType)),]
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey70", color="grey50") +
geom_point(data=locsChurch,color="red",size=5,aes(y=reprLat,x=reprLong)) +
geom_point(data=locsSettlement,alpha=.7,size=2,aes(y=reprLat,x=reprLong,color=epoch)) +
coord_sf(xlim = c(-15,50), ylim = c(20,75), expand = FALSE) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "bl", width_hint = 0.25) +
annotation_north_arrow(location = "bl", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Settlements and Churches timelaps of {closest_state} period", subtitle = "Frame {frame} of {nframes}")+
labs(color = "Timeperiods")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
# transition_states(epoch,
# transition_length = 3,
# state_length = 100,
# wrap = FALSE)+
# enter_fade()+
# exit_fade()
ourPlot
## Warning: Removed 2 rows containing missing values (geom_point).
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="settlements_in_different_timeperiods.png",plot=ourPlot,dpi=300,width=7,height=5)
## Warning: Removed 2 rows containing missing values (geom_point).
## Scale on map varies by more than 10%, scale bar may be inaccurate
Europop packageThe europop package has information on population of european cities, which we can now map. There are two main tables: europop with the historical populations of European cities, and city_coordsâwith the latitudes and longitudes of those cities. With this new data you now should be able to map European cities. Your task is as follows:
google it!)#install.packages("europop")
library(dplyr)
library(tidyverse)
## -- Attaching packages --------------------------------------------------------------------------------------------------------------------------- tidyverse 1.2.1 --
## v tibble 2.1.1 v purrr 0.3.2
## v tidyr 0.8.3 v stringr 1.4.0
## v readr 1.3.1 v forcats 0.4.0
## -- Conflicts ------------------------------------------------------------------------------------------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library(europop)
library(ggplot2)
library(ggspatial)
library(gganimate)
biggestCities <- europop %>%
filter(population >= 305 & year == 1800)
new_data <- data.frame("region" = c("Scandinavia", "England and Wales", "Scotland", "Ireland", "The Netherlands", "Belgium", "Germany", "France", "Switzerland", "Northern Italy", "Central Italy", "Souther Italy", "Spain", "Portual", "Austria and Czechoslovakia", "Poland"), "long" = c(15.150000, -1.210000, -3.900000, -7.480000, 6.220000, 4.810000, 9.800000, 2.250000, 8.060000, 10.170000, 12.354946, 16.581014, -2.939996, -8.346877, 16.456718, 17.009529), "lat" = c(61.400000, 51.980000, 56.960000, 52.690000, 52.990000, 50.900000, 50.500000, 48.290000, 46.890000, 45.337603, 42.139779, 39.170254, 39.664747, 48.686041, 48.509328, 51.862042))
europopCoor <- left_join(europop, new_data, by = "region")
## Warning: Column `region` joining character vector and factor, coercing into
## character vector
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey80", color="grey50") +
geom_count(data=europopCoor,alpha=.6,aes(y=lat,x=long,color=region,size=population), na.rm=TRUE) +
geom_count(data=europopCoor,color="red",alpha=.6,aes(y=63,x=0,size=population), na.rm=TRUE) +
coord_sf(xlim = c(-13,30), ylim = c(35,70), expand = FALSE) +
geom_text(x=-0.241680+.5, y=51.528558+.1, label="London", color="black", size=4) +
geom_text(x=2.2770205+.5, y=48.858837+.1, label="Paris", color="black", size=4) +
geom_text(x=14.1765627+.5, y=40.853912+.1, label="Napoli", color="black", size=4) +
geom_text(x=4.828583+.5, y=52.354627+.1, label="Amsterdam", color="black", size=4) +
geom_text(x=12.395915+.5, y=41.909986+.1, label="Rome", color="black", size=4) +
geom_text(x=-6.385785+.5, y=53.324238+.1, label="Dublin", color="black", size=4) +
geom_text(x=-3.819619+.5, y=40.437869+.1, label="Madrid", color="black", size=4) +
geom_text(x=16.363449+.5, y=48.210033+.1, label="vienna", color="black", size=4) +
geom_text(x=13.284650+.5, y=52.506761+.1, label="Berlin", color="black", size=4) +
geom_text(x=-9.195222+.5, y=38.743621+.1, label="Lisboa", color="black", size=4) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Population timelaps of {closest_state}", subtitle = "Frame {frame} of {nframes}")+
labs(color = "Regions", size = "Aggregated Population")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
# transition_states(year,
# transition_length = 5,
# state_length = 100,
# wrap = FALSE)+
# enter_fade()+
# exit_fade()
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="european_population_timelaps.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
library(dplyr)
library(tidyverse)
library(europop)
library(ggplot2)
library(ggspatial)
library(gganimate)
unique(europop$year)
## [1] 1500 1550 1600 1650 1700 1750 1800
biggestCities <- europop %>%
filter(population >= 150)
europopRen <- europop %>%
filter(year == 1500) %>%
mutate(period = "Rennaissance")
europopRef <- europop %>%
filter(year == 1550) %>%
mutate(period = "Reformation")
europopWar <- europop %>%
filter(year == 1600) %>%
mutate(period = "30 Years War")
europopWar2 <- europop %>%
filter(year == 1650) %>%
mutate(period = "30 Years War")
europopRom <- europop %>%
filter(year == 1700) %>%
mutate(period = "Romatic")
europopRom2 <- europop %>%
filter(year == 1750) %>%
mutate(period = "Romatic")
europopHist <- europop %>%
filter(year == 1800) %>%
mutate(period = "Historicism")
europopPeriods <- full_join(europopRen, europopRef)
## Joining, by = c("city", "region", "year", "population", "period")
europopPeriods <- full_join(europopPeriods, europopWar)
## Joining, by = c("city", "region", "year", "population", "period")
europopPeriods <- full_join(europopPeriods, europopWar2)
## Joining, by = c("city", "region", "year", "population", "period")
europopPeriods <- full_join(europopPeriods, europopRom)
## Joining, by = c("city", "region", "year", "population", "period")
europopPeriods <- full_join(europopPeriods, europopRom2)
## Joining, by = c("city", "region", "year", "population", "period")
europopPeriods <- full_join(europopPeriods, europopHist)
## Joining, by = c("city", "region", "year", "population", "period")
europopPeriodsCoor <- left_join(europopCoor, europopPeriods)
## Joining, by = c("city", "region", "year", "population")
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey80", color="grey50") +
geom_count(data=europopPeriodsCoor,alpha=.6,aes(y=lat,x=long,color=region,size=population), na.rm=TRUE) +
coord_sf(xlim = c(-13,30), ylim = c(35,70), expand = FALSE) +
geom_text(x=-0.241680+.5, y=51.528558-.3, label="London", color="black", size=4) +
geom_point(x=-0.241680+.5, y=51.528558, color="black", size=2, shape=2) +
geom_text(x=2.2770205+.5, y=48.858837-.3, label="Paris", color="black", size=4) +
geom_point(x=2.2770205+.5, y=48.858837, color="black", size=2, shape=2) +
geom_text(x=14.1765627+.5, y=40.853912-.3, label="Napoli", color="black", size=4) +
geom_point(x=14.1765627+.5, y=40.853912, color="black", size=2, shape=2) +
geom_text(x=4.828583+.5, y=52.354627-.3, label="Amsterdam", color="black", size=4) +
geom_point(x=4.828583+.5, y=52.354627, color="black", size=2, shape=2) +
geom_text(x=12.395915+.5, y=41.909986-.3, label="Rome", color="black", size=4) +
geom_point(x=12.395915+.5, y=41.909986, color="black", size=2, shape=2) +
geom_text(x=-6.385785+.5, y=53.324238-.3, label="Dublin", color="black", size=4) +
geom_point(x=-6.385785+.5, y=53.324238, color="black", size=2, shape=2) +
geom_text(x=-3.819619+.5, y=40.437869+.3, label="Madrid", color="black", size=4) +
geom_point(x=-3.819619+.5, y=40.437869, color="black", size=2, shape=2) +
geom_text(x=16.363449+.5, y=48.210033-.3, label="vienna", color="black", size=4) +
geom_point(x=16.363449+.5, y=48.210033, color="black", size=2, shape=2) +
geom_text(x=13.284650+.5, y=52.506761-.3, label="Berlin", color="black", size=4) +
geom_point(x=13.284650+.5, y=52.506761, color="black", size=2, shape=2) +
geom_text(x=-9.195222+.5, y=38.743621-.3, label="Lisboa", color="black", size=4) +
geom_point(x=-9.195222+.5, y=38.743621, color="black", size=2, shape=2) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Population timelaps during {closest_state}", subtitle = "Frame {frame} of {nframes}")+
labs(color = "Periods", size = "Aggregated Population")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
# transition_states(period,
# transition_length = 5,
# state_length = 100,
# wrap = FALSE)+
# enter_fade()+
# exit_fade()
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="european_population_timelaps_periods.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
Rennaissance <- europopPeriodsCoor %>%
filter(period=="Rennaissance")
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey80", color="grey50") +
geom_count(data=Rennaissance,alpha=.2,aes(y=lat,x=long,color=region,size=population), na.rm=TRUE) +
coord_sf(xlim = c(-13,30), ylim = c(35,70), expand = FALSE) +
geom_text(x=-0.241680+.5, y=51.528558-.3, label="London", color="black", size=3) +
geom_point(x=-0.241680+.5, y=51.528558, color="black", size=1, shape=2) +
geom_text(x=2.2770205+.5, y=48.858837-.3, label="Paris", color="black", size=3) +
geom_point(x=2.2770205+.5, y=48.858837, color="black", size=1, shape=2) +
geom_text(x=14.1765627+.5, y=40.853912-.3, label="Napoli", color="black", size=3) +
geom_point(x=14.1765627+.5, y=40.853912, color="black", size=1, shape=2) +
geom_text(x=4.828583+.5, y=52.354627-.3, label="Amsterdam", color="black", size=3) +
geom_point(x=4.828583+.5, y=52.354627, color="black", size=1, shape=2) +
geom_text(x=12.395915+.5, y=41.909986-.3, label="Rome", color="black", size=3) +
geom_point(x=12.395915+.5, y=41.909986, color="black", size=1, shape=2) +
geom_text(x=-6.385785+.5, y=53.324238-.3, label="Dublin", color="black", size=3) +
geom_point(x=-6.385785+.5, y=53.324238, color="black", size=1, shape=2) +
geom_text(x=-3.819619+.5, y=40.437869+.3, label="Madrid", color="black", size=3) +
geom_point(x=-3.819619+.5, y=40.437869, color="black", size=1, shape=2) +
geom_text(x=16.363449+.5, y=48.210033-.3, label="vienna", color="black", size=3) +
geom_point(x=16.363449+.5, y=48.210033, color="black", size=1, shape=2) +
geom_text(x=13.284650+.5, y=52.506761-.3, label="Berlin", color="black", size=3) +
geom_point(x=13.284650+.5, y=52.506761, color="black", size=1, shape=2) +
geom_text(x=-9.195222+.5, y=38.743621-.3, label="Lisboa", color="black", size=3) +
geom_point(x=-9.195222+.5, y=38.743621, color="black", size=1, shape=2) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Population during Rennaissance around 1500", subtitle = "")+
labs(color = "Regions", size = "Aggregated Population in 1000")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="european_population_period_rennaissance.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
Reformation <- europopPeriodsCoor %>%
filter(period=="Reformation")
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey80", color="grey50") +
geom_count(data=Reformation,alpha=.2,aes(y=lat,x=long,color=region,size=population), na.rm=TRUE) +
coord_sf(xlim = c(-13,30), ylim = c(35,70), expand = FALSE) +
geom_text(x=-0.241680+.5, y=51.528558-.3, label="London", color="black", size=3) +
geom_point(x=-0.241680+.5, y=51.528558, color="black", size=1, shape=2) +
geom_text(x=2.2770205+.5, y=48.858837-.3, label="Paris", color="black", size=3) +
geom_point(x=2.2770205+.5, y=48.858837, color="black", size=1, shape=2) +
geom_text(x=14.1765627+.5, y=40.853912-.3, label="Napoli", color="black", size=3) +
geom_point(x=14.1765627+.5, y=40.853912, color="black", size=1, shape=2) +
geom_text(x=4.828583+.5, y=52.354627-.3, label="Amsterdam", color="black", size=3) +
geom_point(x=4.828583+.5, y=52.354627, color="black", size=1, shape=2) +
geom_text(x=12.395915+.5, y=41.909986-.3, label="Rome", color="black", size=3) +
geom_point(x=12.395915+.5, y=41.909986, color="black", size=1, shape=2) +
geom_text(x=-6.385785+.5, y=53.324238-.3, label="Dublin", color="black", size=3) +
geom_point(x=-6.385785+.5, y=53.324238, color="black", size=1, shape=2) +
geom_text(x=-3.819619+.5, y=40.437869+.3, label="Madrid", color="black", size=3) +
geom_point(x=-3.819619+.5, y=40.437869, color="black", size=1, shape=2) +
geom_text(x=16.363449+.5, y=48.210033-.3, label="vienna", color="black", size=3) +
geom_point(x=16.363449+.5, y=48.210033, color="black", size=1, shape=2) +
geom_text(x=13.284650+.5, y=52.506761-.3, label="Berlin", color="black", size=3) +
geom_point(x=13.284650+.5, y=52.506761, color="black", size=1, shape=2) +
geom_text(x=-9.195222+.5, y=38.743621-.3, label="Lisboa", color="black", size=3) +
geom_point(x=-9.195222+.5, y=38.743621, color="black", size=1, shape=2) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Population during Reformation around 1550", subtitle = "")+
labs(color = "Regions", size = "Aggregated Population in 1000")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="european_population_period_reformation.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
war <- europopPeriodsCoor %>%
filter(period=="30 Years War")
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey80", color="grey50") +
geom_count(data=war,alpha=.2,aes(y=lat,x=long,color=region,size=population), na.rm=TRUE) +
coord_sf(xlim = c(-13,30), ylim = c(35,70), expand = FALSE) +
geom_text(x=-0.241680+.5, y=51.528558-.3, label="London", color="black", size=3) +
geom_point(x=-0.241680+.5, y=51.528558, color="black", size=1, shape=2) +
geom_text(x=2.2770205+.5, y=48.858837-.3, label="Paris", color="black", size=3) +
geom_point(x=2.2770205+.5, y=48.858837, color="black", size=1, shape=2) +
geom_text(x=14.1765627+.5, y=40.853912-.3, label="Napoli", color="black", size=3) +
geom_point(x=14.1765627+.5, y=40.853912, color="black", size=1, shape=2) +
geom_text(x=4.828583+.5, y=52.354627-.3, label="Amsterdam", color="black", size=3) +
geom_point(x=4.828583+.5, y=52.354627, color="black", size=1, shape=2) +
geom_text(x=12.395915+.5, y=41.909986-.3, label="Rome", color="black", size=3) +
geom_point(x=12.395915+.5, y=41.909986, color="black", size=1, shape=2) +
geom_text(x=-6.385785+.5, y=53.324238-.3, label="Dublin", color="black", size=3) +
geom_point(x=-6.385785+.5, y=53.324238, color="black", size=1, shape=2) +
geom_text(x=-3.819619+.5, y=40.437869+.3, label="Madrid", color="black", size=3) +
geom_point(x=-3.819619+.5, y=40.437869, color="black", size=1, shape=2) +
geom_text(x=16.363449+.5, y=48.210033-.3, label="vienna", color="black", size=3) +
geom_point(x=16.363449+.5, y=48.210033, color="black", size=1, shape=2) +
geom_text(x=13.284650+.5, y=52.506761-.3, label="Berlin", color="black", size=3) +
geom_point(x=13.284650+.5, y=52.506761, color="black", size=1, shape=2) +
geom_text(x=-9.195222+.5, y=38.743621-.3, label="Lisboa", color="black", size=3) +
geom_point(x=-9.195222+.5, y=38.743621, color="black", size=1, shape=2) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Population during 30 Years of War from 1600 to 1650", subtitle = "")+
labs(color = "Regions", size = "Aggregated Population in 1000")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="european_population_period_war.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
historicism <- europopPeriodsCoor %>%
filter(period=="Historicism")
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey80", color="grey50") +
geom_count(data=historicism,alpha=.2,aes(y=lat,x=long,color=region,size=population), na.rm=TRUE) +
coord_sf(xlim = c(-13,30), ylim = c(35,70), expand = FALSE) +
geom_text(x=-0.241680+.5, y=51.528558-.3, label="London", color="black", size=3) +
geom_point(x=-0.241680+.5, y=51.528558, color="black", size=1, shape=2) +
geom_text(x=2.2770205+.5, y=48.858837-.3, label="Paris", color="black", size=3) +
geom_point(x=2.2770205+.5, y=48.858837, color="black", size=1, shape=2) +
geom_text(x=14.1765627+.5, y=40.853912-.3, label="Napoli", color="black", size=3) +
geom_point(x=14.1765627+.5, y=40.853912, color="black", size=1, shape=2) +
geom_text(x=4.828583+.5, y=52.354627-.3, label="Amsterdam", color="black", size=3) +
geom_point(x=4.828583+.5, y=52.354627, color="black", size=1, shape=2) +
geom_text(x=12.395915+.5, y=41.909986-.3, label="Rome", color="black", size=3) +
geom_point(x=12.395915+.5, y=41.909986, color="black", size=1, shape=2) +
geom_text(x=-6.385785+.5, y=53.324238-.3, label="Dublin", color="black", size=3) +
geom_point(x=-6.385785+.5, y=53.324238, color="black", size=1, shape=2) +
geom_text(x=-3.819619+.5, y=40.437869+.3, label="Madrid", color="black", size=3) +
geom_point(x=-3.819619+.5, y=40.437869, color="black", size=1, shape=2) +
geom_text(x=16.363449+.5, y=48.210033-.3, label="vienna", color="black", size=3) +
geom_point(x=16.363449+.5, y=48.210033, color="black", size=1, shape=2) +
geom_text(x=13.284650+.5, y=52.506761-.3, label="Berlin", color="black", size=3) +
geom_point(x=13.284650+.5, y=52.506761, color="black", size=1, shape=2) +
geom_text(x=-9.195222+.5, y=38.743621-.3, label="Lisboa", color="black", size=3) +
geom_point(x=-9.195222+.5, y=38.743621, color="black", size=1, shape=2) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Population during Historicism around 1800", subtitle = "")+
labs(color = "Regions", size = "Aggregated Population in 1000")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="european_population_period_historicism.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate
romantic <- europopPeriodsCoor %>%
filter(period=="Romantic")
ourPlot <- ggplot(data = world) +
geom_sf(fill="grey80", color="grey50") +
geom_count(data=romantic,alpha=.2,aes(y=lat,x=long,color=region,size=population), na.rm=TRUE) +
coord_sf(xlim = c(-13,30), ylim = c(35,70), expand = FALSE) +
geom_text(x=-0.241680+.5, y=51.528558-.3, label="London", color="black", size=3) +
geom_point(x=-0.241680+.5, y=51.528558, color="black", size=1, shape=2) +
geom_text(x=2.2770205+.5, y=48.858837-.3, label="Paris", color="black", size=3) +
geom_point(x=2.2770205+.5, y=48.858837, color="black", size=1, shape=2) +
geom_text(x=14.1765627+.5, y=40.853912-.3, label="Napoli", color="black", size=3) +
geom_point(x=14.1765627+.5, y=40.853912, color="black", size=1, shape=2) +
geom_text(x=4.828583+.5, y=52.354627-.3, label="Amsterdam", color="black", size=3) +
geom_point(x=4.828583+.5, y=52.354627, color="black", size=1, shape=2) +
geom_text(x=12.395915+.5, y=41.909986-.3, label="Rome", color="black", size=3) +
geom_point(x=12.395915+.5, y=41.909986, color="black", size=1, shape=2) +
geom_text(x=-6.385785+.5, y=53.324238-.3, label="Dublin", color="black", size=3) +
geom_point(x=-6.385785+.5, y=53.324238, color="black", size=1, shape=2) +
geom_text(x=-3.819619+.5, y=40.437869+.3, label="Madrid", color="black", size=3) +
geom_point(x=-3.819619+.5, y=40.437869, color="black", size=1, shape=2) +
geom_text(x=16.363449+.5, y=48.210033-.3, label="vienna", color="black", size=3) +
geom_point(x=16.363449+.5, y=48.210033, color="black", size=1, shape=2) +
geom_text(x=13.284650+.5, y=52.506761-.3, label="Berlin", color="black", size=3) +
geom_point(x=13.284650+.5, y=52.506761, color="black", size=1, shape=2) +
geom_text(x=-9.195222+.5, y=38.743621-.3, label="Lisboa", color="black", size=3) +
geom_point(x=-9.195222+.5, y=38.743621, color="black", size=1, shape=2) +
theme(panel.grid.major = element_line(color = gray(.1), linetype = "dotted", size = 0.5),
panel.background = element_rect(fill = "grey90")) +
xlab("Longitude") + ylab("Latitude") +
annotation_scale(location = "br", width_hint = 0.25) +
annotation_north_arrow(location = "br", which_north = "true",
pad_x = unit(0.0, "in"), pad_y = unit(0.2, "in"),
style = north_arrow_fancy_orienteering) +
#xlab("") + ylab("") +
ggtitle("Population during Romantic period from 1700 to 1750", subtitle = "")+
labs(color = "Regions", size = "Aggregated Population in 1000")+
theme(legend.box = "horizontal",
legend.box.margin = margin(0.2, 0.01, 0.1, 0.01, "cm"),
legend.margin = margin(1.5, 0.01, 0.01, 0.5, "cm"),
legend.direction = "vertical",
legend.spacing = unit(0.01, "cm"),
legend.text = element_text(size=8),
legend.title = element_text(size=10))
# Legend Documentation: https://www.datanovia.com/en/blog/ggplot-legend-title-position-and-labels/
ourPlot
## Scale on map varies by more than 10%, scale bar may be inaccurate
ggsave(file="european_population_period_romantic.png",plot=ourPlot,dpi=300,width=7,height=5)
## Scale on map varies by more than 10%, scale bar may be inaccurate